#ifndef GACHROMOSOME_H
#define GACHROMOSOME_H
#include "stdio.h"
#include "stdlib.h"

class GAChromosome
{
 private:
  unsigned long m_nID; //unique id in pools
  float m_fScore; //the higher it is, the better it is
 private:
  int m_nGene;
  int *m_pGenes;
 public:
  GAChromosome();
  GAChromosome(unsigned long ulID);
  GAChromosome(unsigned long ulID, int nGene);
  GAChromosome(unsigned long ulID, int nGene, const int* pGenes);
  ~GAChromosome();
 protected:
  void init(unsigned long ulID, int nGene, const int* pGenes);
  void clean(void);
 public:
  void SetUniqueID(unsigned long ulID);
  int SetGeneCount(int nCount);
  int& Gene(int index);
  int& operator[](const int index);
  float& Score(void); //score
  int CopyOfGene(unsigned long ulID, GAChromosome* pSrc);
  unsigned long GetUniqueID(void);
  int GetGeneCount(); //gene count
};

int SaveChromosome(FILE*& pHandle, GAChromosome* pChromosome);
int LoadChromosome(FILE*& pHandle, GAChromosome* pChromosoem);

////////////////////////////////////////////////////////////////////////////////////////////////////////

//run cross-over operation on two specified chromosomes
/*
  \param           pFstParent        parent I
  \param           pSecParent        parent II
  \param           pFstChild[out]    child I
  \param           pSecChild[out]    child II
  \param           nType             cross-over type
  \return          0                 ok
  \return          < 0               error
 */
int GACrossOver(GAChromosome* pFstParent, GAChromosome* pSecParent,
		GAChromosome* pFstChild, GAChromosome* pSecChlid, int nType);

//run mutation on specified chromosome
/*
  \param          pChromosome[in/out]        chromosome operated on
  \param          nType                      Mutation type
  \return         0                          ok
  \return         < 0                        error
 */
int GAMutation(GAChromosome* pChromesome, int nType);

//run scale on specified chromosome
/*
  \param		pChromosome		chromosome operated on
  \param		fFactor			factor
  \return       0				ok
  \return       < 0				error
 */
int GAScale(GAChromosome* pChromosome, float fFactor);


#endif
